package study.nosql.neo4j.support.neo4j;

import lombok.extern.slf4j.Slf4j;
import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;

@Slf4j
@org.springframework.context.annotation.Configuration
@EnableNeo4jRepositories(basePackages = "study.nosql.neo4j.repository")
public class Neo4jConfig {

    @Value("${spring.data.neo4j.uri}")
    private String uri;
    @Value("${spring.data.neo4j.username}")
    private String userName;
    @Value("${spring.data.neo4j.password}")
    private String password;

    @Bean
    public Configuration configuration() {
        Configuration configuration = new Configuration.Builder()
                .uri(uri)
                .connectionPoolSize(100)
                .credentials(userName, password)
                .withBasePackages("study.nosql.neo4j.repository")
                .build();
        return configuration;
    }

    @Bean
    public SessionFactory sessionFactory(Configuration configuration) {
        return new SessionFactory(configuration);
    }

    @Bean
    public Neo4jTransactionManager transactionManager(SessionFactory sessionFactory) {
        return new Neo4jTransactionManager(sessionFactory);
    }
}
